// Package vehicle 模型
package vehicle

import (
	// "gitee.com/sweetsunnyflower/carpooling-server-go/pkg/logger"
	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models"
	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models/fuel_type"
	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models/transmission_type"
	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models/vehicle_brand"
	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models/vehicle_model"
	"gitee.com/sweetsunnyflower/carpooling-server-go/pkg/database"
)

type Vehicle struct {
	models.BaseModel

	BrandId        uint64                              `gorm:"column:brand_id" db:"brand_id" json:"brand_id" form:"brand_id"`                             //车辆品牌
	ModelId        uint64                              `gorm:"column:model_id" db:"model_id" json:"model_id" form:"model_id"`                             //车辆型号
	Year           models.FormatTime                   `gorm:"column:year;type:timestamp;" db:"year" json:"year" form:"year"`                             //车辆出厂日期
	Color          string                              `gorm:"type:varchar(255)" db:"color" json:"color" form:"color"`                                    //颜色
	LicensePlate   string                              `gorm:"type:varchar(255)" db:"license_plate" json:"license_plate" form:"license_plate"`            //车牌号
	Mileage        float64                             `gorm:"column:mileage" db:"mileage" json:"mileage" form:"mileage"`                                 //行驶公里数
	FuelId         uint64                              `gorm:"column:fuel_id" db:"fuel_type" json:"fuel_id" form:"fuel_id"`                               //燃油类型
	TransmissionId uint64                              `gorm:"column:transmission_id" db:"transmission_id" json:"transmission_id" form:"transmission_id"` //变速器类型
	EngineSize     float64                             `gorm:"column:engine_size" db:"engine_size" json:"engine_size" form:"engine_size"`                 //发动机排量
	Seats          uint8                               `gorm:"column:seats" db:"seats" json:"seats" form:"seats"`                                         //座位数
	UserId         uint64                              `gorm:"column:user_id" db:"user_id" json:"user_id" form:"user_id"`
	Brand          *vehicle_brand.VehicleBrand         `json:"brand"`
	Model          *vehicle_model.VehicleModel         `json:"model"`
	Fuels          *fuel_type.FuelType                 `gorm:"foreignKey:FuelId" json:"fuels"`
	Transmissions  *transmission_type.TransmissionType `gorm:"foreignKey:TransmissionId" json:"transmissions"`

	models.CommonTimestampsField
}

func (vehicle *Vehicle) Create() {
	database.DB.Create(&vehicle)
}

func (vehicle *Vehicle) Save() (rowsAffected int64) {
	result := database.DB.Save(&vehicle)
	return result.RowsAffected
}

func (vehicle *Vehicle) Delete() (rowsAffected int64) {
	result := database.DB.Delete(&vehicle)
	return result.RowsAffected
}
